package com.ll.daipao.config;

import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * 微信公众号主配置
 * <p>
 * Created by bjliumingbo on 2017/5/12.
 *
 * @author FirenzesEagle
 * @author BinaryWang
 */
@Configuration
public class MainConfiguration {
	@Value("${wxProperties.appId}")
	private String appId;

	@Value("${wxProperties.appSecret}")
	private String appSecret;

	@Value("${wxProperties.token}")
	private String token;

	@Value("${wxProperties.aesKey}")
	private String aesKey;

    @Value("${wxProperties.appId2}")
    private String appId2;

    @Value("${wxProperties.appSecret2}")
    private String appSecret2;

    @Value("${wxProperties.token2}")
    private String token2;

    @Value("${wxProperties.aesKey2}")
    private String aesKey2;

    public String getAppId2() {
        return appId2;
    }

    public void setAppId2(String appId2) {
        this.appId2 = appId2;
    }

    public String getAppSecret2() {
        return appSecret2;
    }

    public void setAppSecret2(String appSecret2) {
        this.appSecret2 = appSecret2;
    }

    public String getToken2() {
        return token2;
    }

    public void setToken2(String token2) {
        this.token2 = token2;
    }

    public String getAesKey2() {
        return aesKey2;
    }

    public void setAesKey2(String aesKey2) {
        this.aesKey2 = aesKey2;
    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getAesKey() {
        return aesKey;
    }

    public void setAesKey(String aesKey) {
        this.aesKey = aesKey;
    }

    @Bean
    @Primary
	public WxMpConfigStorage wxMpConfigStorage() {
		WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
		configStorage.setAppId(this.appId);
		configStorage.setSecret(this.appSecret);
		configStorage.setToken(this.token);
		configStorage.setAesKey(this.aesKey);
		return configStorage;
	}

    @Bean
    public WxMpConfigStorage wxMpConfigStorage2() {
        WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
        configStorage.setAppId(this.appId2);
        configStorage.setSecret(this.appSecret2);
        configStorage.setToken(this.token2);
        configStorage.setAesKey(this.aesKey2);
        return configStorage;
    }

	@Bean
    @Primary
	public WxMpService wxMpService() {
		WxMpService wxMpService = new WxMpServiceImpl();
		wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
		return wxMpService;
	}

    @Bean
    public WxMpService wxMpService2() {
        WxMpService WxMpService2 = new WxMpServiceImpl();
        WxMpService2.setWxMpConfigStorage(wxMpConfigStorage2());
        return WxMpService2;

    }

}
